package com.yunshipei.ui.dialog;

import android.content.res.Resources;
import android.graphics.drawable.PaintDrawable;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.yunshipei.enterplorer.R;

/**
 * Created by cike on 16/9/19.
 */
public class PopupWindowUtil {

    public static void showIMPlusPopup(View view, final CreateGroupListener listener1, final MassTextListener listener2) {
        TextView createGroup, massText;
        if (view == null)
            return;
        // 一个自定义的布局，作为显示的内容
        View contentView = LayoutInflater.from(view.getContext()).inflate(
                R.layout.im_plus_popupwindow_layout, null);
        createGroup = (TextView) contentView.findViewById(R.id.create_group);
        massText = (TextView) contentView.findViewById(R.id.mass_text);
        final PopupWindow popupWindow = new PopupWindow(contentView,
                ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(view.getContext().getResources().getDrawable(R.drawable.im_create_menu));
        popupWindow.setTouchInterceptor(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return false;
            }
        });
        createGroup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener1.onClick(v);
                popupWindow.dismiss();
            }
        });

        massText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                listener2.onClick(v);
                popupWindow.dismiss();
            }
        });
        popupWindow.showAsDropDown(view,0, -14);
    }

    public interface CreateGroupListener {
        void onClick(View view);
    }

    public interface MassTextListener {
        void onClick(View view);
    }
}
